home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-s-cs.cc < prev    next >
C/C++ Source or Header  |  1996-10-15  |  7KB  |  248 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-scalar.h"
  34. #include "ov-complex.h"
  35. #include "ov-cx-mat.h"
  36. #include "ov-typeinfo.h"
  37. #include "op-s-cs.h"
  38. #include "ops.h"
  39. #include "xdiv.h"
  40. #include "xpow.h"
  41.  
  42. // scalar by complex scalar ops.
  43.  
  44. static octave_value
  45. add (const octave_value& a1, const octave_value& a2)
  46. {
  47.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  48.  
  49.   return octave_value (v1.double_value () + v2.complex_value ());
  50. }
  51.  
  52. static octave_value
  53. sub (const octave_value& a1, const octave_value& a2)
  54. {
  55.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  56.  
  57.   return octave_value (v1.double_value () - v2.complex_value ());
  58. }
  59.  
  60. static octave_value
  61. mul (const octave_value& a1, const octave_value& a2)
  62. {
  63.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  64.  
  65.   return octave_value (v1.double_value () * v2.complex_value ());
  66. }
  67.  
  68. static octave_value
  69. div (const octave_value& a1, const octave_value& a2)
  70. {
  71.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  72.  
  73.   Complex d = v2.complex_value ();
  74.  
  75.   if (d == 0.0)
  76.     gripe_divide_by_zero ();
  77.  
  78.   return octave_value (v1.double_value () / d);
  79. }
  80.  
  81. static octave_value
  82. pow (const octave_value& a1, const octave_value& a2)
  83. {
  84.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  85.  
  86.   return xpow (v1.double_value (), v2.complex_value ());
  87. }
  88.  
  89. static octave_value
  90. ldiv (const octave_value& a1, const octave_value& a2)
  91. {
  92.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  93.  
  94.   double d = v1.double_value ();
  95.  
  96.   if (d == 0.0)
  97.     gripe_divide_by_zero ();
  98.  
  99.   return octave_value (v2.complex_value () / d);
  100. }
  101.  
  102. static octave_value
  103. lt (const octave_value& a1, const octave_value& a2)
  104. {
  105.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  106.  
  107.   return octave_value (v1.double_value () < v2.double_value ());
  108. }
  109.  
  110. static octave_value
  111. le (const octave_value& a1, const octave_value& a2)
  112. {
  113.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  114.  
  115.   return octave_value (v1.double_value () <= v2.double_value ());
  116. }
  117.  
  118. static octave_value
  119. eq (const octave_value& a1, const octave_value& a2)
  120. {
  121.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  122.  
  123.   return octave_value (v1.double_value () == v2.complex_value ());
  124. }
  125.  
  126. static octave_value
  127. ge (const octave_value& a1, const octave_value& a2)
  128. {
  129.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  130.  
  131.   return octave_value (v1.double_value () >= v2.double_value ());
  132. }
  133.  
  134. static octave_value
  135. gt (const octave_value& a1, const octave_value& a2)
  136. {
  137.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  138.  
  139.   return octave_value (v1.double_value () > v2.double_value ());
  140. }
  141.  
  142. static octave_value
  143. ne (const octave_value& a1, const octave_value& a2)
  144. {
  145.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  146.  
  147.   return octave_value (v1.double_value () != v2.complex_value ());
  148. }
  149.  
  150. static octave_value
  151. el_mul (const octave_value& a1, const octave_value& a2)
  152. {
  153.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  154.  
  155.   return octave_value (v1.double_value () * v2.complex_value ());
  156. }
  157.  
  158. static octave_value
  159. el_div (const octave_value& a1, const octave_value& a2)
  160. {
  161.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  162.  
  163.   Complex d = v2.complex_value ();
  164.  
  165.   if (d == 0.0)
  166.     gripe_divide_by_zero ();
  167.  
  168.   return octave_value (v1.double_value () / d);
  169. }
  170.  
  171. static octave_value
  172. el_pow (const octave_value& a1, const octave_value& a2)
  173. {
  174.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  175.  
  176.   return xpow (v1.double_value (), v2.complex_value ());
  177. }
  178.  
  179. static octave_value
  180. el_ldiv (const octave_value& a1, const octave_value& a2)
  181. {
  182.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  183.  
  184.   double d = v1.double_value ();
  185.  
  186.   if (d == 0.0)
  187.     gripe_divide_by_zero ();
  188.  
  189.   return octave_value (v2.complex_value () / d);
  190. }
  191.  
  192. static octave_value
  193. el_and (const octave_value& a1, const octave_value& a2)
  194. {
  195.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  196.  
  197.   return octave_value (v1.double_value () && (v2.complex_value () != 0.0));
  198. }
  199.  
  200. static octave_value
  201. el_or (const octave_value& a1, const octave_value& a2)
  202. {
  203.   CAST_BINOP_ARGS (const octave_scalar&, const octave_complex&);
  204.  
  205.   return octave_value (v1.double_value () || (v2.complex_value () != 0.0));
  206. }
  207.  
  208. static octave_value *
  209. complex_matrix_conv (const octave_value& a)
  210. {
  211.   CAST_CONV_ARG (const octave_scalar&);
  212.  
  213.   return new octave_complex_matrix (v.complex_matrix_value ());
  214. }
  215.  
  216. void
  217. install_s_cs_ops (void)
  218. {
  219.   INSTALL_BINOP (add, octave_scalar, octave_complex, add);
  220.   INSTALL_BINOP (sub, octave_scalar, octave_complex, sub);
  221.   INSTALL_BINOP (mul, octave_scalar, octave_complex, mul);
  222.   INSTALL_BINOP (div, octave_scalar, octave_complex, div);
  223.   INSTALL_BINOP (pow, octave_scalar, octave_complex, pow);
  224.   INSTALL_BINOP (ldiv, octave_scalar, octave_complex, ldiv);
  225.   INSTALL_BINOP (lt, octave_scalar, octave_complex, lt);
  226.   INSTALL_BINOP (le, octave_scalar, octave_complex, le);
  227.   INSTALL_BINOP (eq, octave_scalar, octave_complex, eq);
  228.   INSTALL_BINOP (ge, octave_scalar, octave_complex, ge);
  229.   INSTALL_BINOP (gt, octave_scalar, octave_complex, gt);
  230.   INSTALL_BINOP (ne, octave_scalar, octave_complex, ne);
  231.   INSTALL_BINOP (el_mul, octave_scalar, octave_complex, el_mul);
  232.   INSTALL_BINOP (el_div, octave_scalar, octave_complex, el_div);
  233.   INSTALL_BINOP (el_pow, octave_scalar, octave_complex, el_pow);
  234.   INSTALL_BINOP (el_ldiv, octave_scalar, octave_complex, el_ldiv);
  235.   INSTALL_BINOP (el_and, octave_scalar, octave_complex, el_and);
  236.   INSTALL_BINOP (el_or, octave_scalar, octave_complex, el_or);
  237.  
  238.   INSTALL_ASSIGNCONV (octave_scalar, octave_complex, octave_complex_matrix);
  239.  
  240.   INSTALL_WIDENOP (octave_scalar, octave_complex_matrix, complex_matrix_conv);
  241. }
  242.  
  243. /*
  244. ;;; Local Variables: ***
  245. ;;; mode: C++ ***
  246. ;;; End: ***
  247. */
  248.